package injection;

import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * setter 方法依赖注入
 * @author jackcfan
 * @date 2021/9/15
 */
public class XmlSetterInjectionTest {
    @Test
    public void test(){
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        // DefaultListableBeanFactory 实现了注册中心接口
        // XmlBeanDefinitionReader(BeanDefinitionRegistry registry)
        XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

        // 加载 xml 资源，解析并生成 BeanDefinition
        beanDefinitionReader.loadBeanDefinitions("dependency-setter-injection.xml");

        // 依赖查找
        UserHolder userHolder = beanFactory.getBean(UserHolder.class);
        System.out.println(userHolder);

    }
}
